﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="Authors.aspx.cs" Inherits="Admin_Authors" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:SqlDataSource ID="_SDSAuthors" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:DB_BookStoreConnectionString %>" 
        
        InsertCommand="INSERT INTO [Authors] ([AuthorName], [Image], [Description]) VALUES (@AuthorName, @Image, @Description)" 
        OldValuesParameterFormatString="original_{0}" 
        ProviderName="<%$ ConnectionStrings:DB_BookStoreConnectionString.ProviderName %>" 
        SelectCommand="SELECT [AuthorID], [AuthorName], [Image], [Description] FROM [Authors]" 
        DeleteCommand="DELETE FROM [Authors] WHERE [AuthorID] = @original_AuthorID AND [AuthorName] = @original_AuthorName AND (([Image] = @original_Image) OR ([Image] IS NULL AND @original_Image IS NULL)) AND (([Description] = @original_Description) OR ([Description] IS NULL AND @original_Description IS NULL))" 
        UpdateCommand="UPDATE [Authors] SET [AuthorName] = @AuthorName, [Image] = @Image, [Description] = @Description WHERE [AuthorID] = @original_AuthorID AND [AuthorName] = @original_AuthorName AND (([Image] = @original_Image) OR ([Image] IS NULL AND @original_Image IS NULL)) AND (([Description] = @original_Description) OR ([Description] IS NULL AND @original_Description IS NULL))">
        <DeleteParameters>
            <asp:Parameter Name="original_AuthorID" Type="Int32" />
            <asp:Parameter Name="original_AuthorName" Type="String" />
            <asp:Parameter Name="original_Image" Type="String" />
            <asp:Parameter Name="original_Description" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="AuthorName" Type="String" />
            <asp:Parameter Name="Image" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="original_AuthorID" Type="Int32" />
            <asp:Parameter Name="original_AuthorName" Type="String" />
            <asp:Parameter Name="original_Image" Type="String" />
            <asp:Parameter Name="original_Description" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="AuthorName" Type="String" />
            <asp:Parameter Name="Image" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    
    <div id="featured-post">
        <h2>Quản lý thông tin các tác giả</h2>
        <asp:GridView ID="_grdView" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" CellPadding="4" DataKeyNames="AuthorID" 
        DataSourceID="_SDSAuthors" ForeColor="#333333" GridLines="None" 
        onrowcommand="_grdView_RowCommand" style="margin-left: 0px" Width="481px" 
        PageSize="5">
        <PagerSettings Mode="NextPreviousFirstLast" />
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text="Update"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" 
                        CommandName="Delete" onclientclick="return confirm('Delete?');" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="AuthorID" HeaderText="AuthorID" 
                InsertVisible="False" ReadOnly="True" SortExpression="AuthorID" />
            <asp:TemplateField HeaderText="AuthorName" SortExpression="AuthorName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("AuthorName") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton8" runat="server" 
                        CommandArgument='<%# Bind("AuthorID") %>' CommandName="Edit" 
                        Text='<%# Bind("AuthorName") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Description" HeaderText="Description" 
                SortExpression="Description" />
            <asp:TemplateField HeaderText="Image">
                <EditItemTemplate>
                    <br />
                    <table class="style6">
                        <tr>
                            <td class="style7">
                                <asp:Image ID="_imgUpload" runat="server" Height="116px" 
                                    ImageUrl='<%# Bind("Image") %>' Width="124px" />
                            </td>
                            <td>
                                Đường dẫn đến hình:<br />
                                <asp:TextBox ID="_txtUpload" runat="server" Height="22px" ReadOnly="True" 
                                    Text='<%# Bind("Image") %>' Width="212px"></asp:TextBox>
                                <br />
                                Chọn hình mới<br />
                                <asp:FileUpload ID="_fileUpload" runat="server" Height="21px" 
                                    style="margin-bottom: 2px" Width="218px" />
                                <br />
                            </td>
                        </tr>
                    </table>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Image ID="_imgView" runat="server" Height="109px" 
                        ImageUrl='<%# Eval("Image") %>' Width="125px" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerTemplate>
            <asp:LinkButton ID="LinkButton5" runat="server" CausesValidation="False" 
                CommandName="New">New</asp:LinkButton>
            &nbsp;
            <asp:LinkButton ID="LinkButton7" runat="server" CommandName="Page" 
                CommandArgument="Prev" >Previous</asp:LinkButton>
            &nbsp;<asp:LinkButton ID="LinkButton6" runat="server" CommandName="Page" 
                CommandArgument="Next">Next</asp:LinkButton>
        </PagerTemplate>
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <EmptyDataTemplate>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                CellPadding="4" DataKeyNames="AuthorID" DataSourceID="_SDSAuthors" 
                DefaultMode="Insert" ForeColor="#333333" GridLines="None" Height="50px" 
                onitemcommand="DetailsView1_ItemCommand" Width="125px" 
                AutoGenerateInsertButton="True">
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
                <RowStyle BackColor="#EFF3FB" />
                <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <Fields>
                    <asp:BoundField DataField="AuthorID" HeaderText="AuthorID" 
                        InsertVisible="False" ReadOnly="True" SortExpression="AuthorID" />
                    <asp:BoundField DataField="AuthorName" HeaderText="AuthorName" 
                        SortExpression="AuthorName" />
                    <asp:TemplateField HeaderText="Description" SortExpression="Description">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <InsertItemTemplate>
                            <asp:Image ID="_imgNew" runat="server" Height="119px" 
                                ImageUrl='<%# Bind("Image") %>' Width="136px" />
                            <br />
                            Chọn hình:<br />
                            <asp:FileUpload ID="_fileNewUpload" runat="server" />
                            
                            <br />
                            <asp:Button ID="_btnUpload" runat="server" CommandName="NewUpload" 
                                Text="Upload" Width="111px" />
                            
                        </InsertItemTemplate>
                    </asp:TemplateField>
                </Fields>
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#2461BF" />
                <AlternatingRowStyle BackColor="White" />
            </asp:DetailsView>
        </EmptyDataTemplate>
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#0070D1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    </div><!--End .#featured-post-->
</asp:Content>

